package com.hd.crdao.utils;

import android.os.CountDownTimer;
import android.widget.Button;

import com.hd.crdao.R;

/**
 *
 *@author Programming
 *@date 2017/5/25 0025
 */

public class TimeDownCounter extends CountDownTimer {

    private Button mGetcheckcode;

    public TimeDownCounter(long millisInFuture, long countDownInterval, Button getcheckcode) {
        super(millisInFuture, countDownInterval);
        mGetcheckcode = getcheckcode;
    }

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public TimeDownCounter(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (mGetcheckcode != null) {
            mGetcheckcode.setClickable(false);
            mGetcheckcode.setBackgroundResource(R.drawable.shapebutton_press);
            mGetcheckcode.setText("(" + millisUntilFinished / 1000 + ")秒");

        }
    }

    @Override
    public void onFinish() {
        if (mGetcheckcode != null) {
            mGetcheckcode.setClickable(true);
            mGetcheckcode.setText("获取验证码");
            mGetcheckcode.setBackgroundResource(R.drawable.shapebutton);
        }
    }

}

